<?php
session_start();
$user = $_SESSION['user'];

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="../ico/logo.ico" type="image/x-icon" />
    <title>协同办公</title>
    <link rel="stylesheet" href="../../static/css/bootstrap.css">
    <link rel="stylesheet" href="../../static/js/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/main.css">
<style>
    #footer{
        width: 100%;
        height: 50px;
        position: fixed;
        bottom: 0;
        text-align: center;

    }
    #title-form{
        width: 100px;
    }
</style>

</head>
<body>
<div id="logo"><div id="logo-img"><img src="../../static/imaegs/logo/logo2.png"></div>
<div id="logo-right">
    <h5 ><i class="layui-icon" style="font-size: 18px; color: orange">&#xe645;</i>&nbsp;最新公告：<span id="notice"></span></h5>
</div>
</div>
<div id="tiao">
    <div id="left"><a href="index.php"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe68e;</i>&nbsp;首页</a>
    <a href="task_list.php"> <i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe6b2;</i>&nbsp;我的任务</a>
        <a href="file.php"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe621;</i>&nbsp;我的文件</a>
        <a href="user_list.php"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe613;</i>&nbsp;成员信息</a></div>
    <div id="right"><a style="color:grey">您好！&nbsp;</a><input id="user" name="user" readonly="readonly" value="<?php echo $user ?>"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe66f;</i><a href="index.php">个人中心</a>&nbsp;&nbsp;<a onclick="out()" >退出</a></div>
</div>

<div id="from_block">
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this">用户</li>
            <li>任务</li>
            <li>公告</li>
<!--            <li>统计</li>-->
            <li>个人信息</li>

        </ul>
        <div class="layui-tab-content"  >
            <div class="layui-tab-item layui-show">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div id="test1" style="position: fixed;z-index: 9999;margin-left: 60%"></div>
                            <div class="layui-card-header">个人信息</div>
                            <div class="layui-card-body" style="display: flex;flex-direction: row">
                                <div id="head-img"><img src="" id="headImg">
                                <label>我的头像</label>
                                </div>

                                <div id="title">
                                    <label>用户账号：</label><a id="user_name"></a><br>
                                    <label>电话：</label><a id="user_tel"></a><br>
                                    <label>邮箱：</label><a id="user_email"></a>
                                </div>
                                <div id="title" style="width: 50%">
                                    <label>小组名称：</label><a id="user_class"></a><br>
                                    <label>最近任务：</label><a id="user_task" href="task_list.php">无</a><br>
                                    <label>最新公告：</label><a id="user_notice">暂无</a><br>
                                </div>
                            </div>

                            <hr>
                        </div>
                    </div>

                </div>

                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-header">发 布 的 任 务<a id="task-title-all">空空如也</a></div>
                            <div class="layui-card-header">我的团队任务<a id="task-title" href="task_list.php">无</a></div>
                            <div class="layui-card-header">我的个人任务<a id="task-title-self" href="task_list.php">无</a></div>


                        </div>
                    </div>

                </div>

            </div>
            <div class="layui-tab-item">
                <div class="layui-row layui-col-space15" >
                    <div class="layui-col-md12" id="uul">

                    </div>
                </div>




            </div>
            <div class="layui-tab-item">

                <ul class="layui-timeline" id="notice-list">

                </ul>


            </div>
<!--            <div class="layui-tab-item">-->
<!---->
<!--            </div>-->
            <div class="layui-tab-item" id="IDcard">
                <div class="layui-tab-item layui-show">
                    <div class="layui-row layui-col-space15">
                        <div class="layui-col-md12">
                            <div class="layui-card">
                                <div class="layui-card-header" id="message">修改个人信息</div>
                                <div class="layui-card-body" style="display: flex;flex-direction: row">
                                    <div id="from-left">
                                      <div class="layui-form-item">

                                        <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b8;</i>账号：</label>
                                        <div class="layui-input-inline login-inline">
                                            <input type="text" name="userA" id="userA" lay-verify="required" placeholder="请输入用户的帐号" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                        <input type="text" style="display: none" name="id" id="id" >
                                        <input type="text" style="display:none"  name="img-url" id="img-url" >
                                        <div class="layui-form-item">
                                            <label class="layui-form-label login-form" id="title-form" ><i class="iconfont" style="color: #0b3b8c">&#xe6b2;</i>团队名称：</label>
                                            <div class="layui-input-inline login-inline">
                                                <input type="text" name="classA" id="classA"  lay-verify="required" readonly="readonly" placeholder="团队名称" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                        <div class="layui-card-header">修改密码 :&nbsp;&nbsp;  <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="passBox()"><i class="layui-icon"></i></button></div>
                                        <div class="layui-form-item" id="passDiv">
                                            <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b2;</i>密码：</label>
                                            <div class="layui-input-inline login-inline">
                                                <input type="password" name="passA" id="passA" autocomplete="off"  lay-verify="required"  class="layui-input">
                                            </div>
                                            <div class="layui-input-inline login-inline"style="display: none">
                                                <input type="password" name="pass" id="pass" autocomplete="off"  lay-verify="required"  class="layui-input">
                                            </div>
                                        </div>
                                        <div class="layui-card-header">头像设置</div>
                                        <div class="layui-input-block">
                                            <form action="" enctype="multipart/form-data" method="">
                                                <a class="opts_btn" href="JavaScript:void(0)">
                                                    <input  name="myFile" class="oFile" id="oFile"  onchange="FileChangeFn(event)" type="file">
                                                </a>
                                                <label id="file_size"></label><br><br>
                                                <div id="file_box"></div>
                                                <div class="speed_box">
                                                    <div id="speed">0%</div>
                                                </div>
                                                <label id="file_type"></label>
                                                <button class="layui-btn" onclick="UploadFileFn()" type="button">开始上传文件</button>
                                                <div class="clear"></div> <input style="display: none" class="hui-input" id="url" name="url"  type="text">
                                                <br><hr>温馨提示：附件允许的大小为20m<br>
                                                <br>
                                                <br>
                                                <button class="btn btn-warning " lay-submit lay-filter="login" style="float: right" onclick="update()" type="button">确认修改</button>
                                                <div style="height: 100px;width: 100%"></div>
                                            </form>

                                        </div>
                                   </div>
                                    <div id="from-right" style="margin-left: 50px">

                                        <div class="layui-form-item">

                                            <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b8;</i>电话：</label>
                                            <div class="layui-input-inline login-inline">
                                                <input type="text" name="tel" id="tel" lay-verify="required" placeholder="请输入用户电话" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b2;</i>邮箱：</label>
                                            <div class="layui-input-inline login-inline">
                                                <input type="email" name="email" id="email"  lay-verify="required" placeholder="邮箱" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>

            </div>
        </div>
    </div>


</div>

<img id="hua1" src="../../static/imaegs/122.png">
<div id="footer">
    <hr>
    <a id="fot-word">
        版权信息：xianghai保留所有权利，请尊重他人的劳动成果   ||    备案号：蜀ICP备18021117号
        ||           地址：四川省成都市高新区天一街83号软件大楼
    </a>
</div>
<script src="../../static/js/jquery.min.js"></script>
<script src="../../static/js/layui/layui.all.js"></script>

<script>

    function passBox() {
        var passDiv=document.getElementById("passDiv");
        passDiv.style.display="block";
    }
    //获取小组任务的接口
    var user=document.getElementById("user");
    $user=user.value;
$.ajax({
    type: 'post',
    cache: false,
    url: '../../php/user/select_task_user.php?user='+$user,
    data: {

    },
    dataType: 'json',
    success: function (data) {
        $coun = data.count;
        $dat = data.data;
        $timeOver=$dat[0].time_over;



        var taskToal=document.getElementById("task-title");
        taskToal.innerHTML="总共有："+$coun+"项"+"&nbsp;&nbsp;&nbsp;&nbsp;"+"最新一项任务截至时间："+$timeOver;


        var  datea={};
        var new_date = new Date();
        laydate(new_date ,datea);
        function laydate(datea){
            var laydate = layui.laydate;
            var array = new Array();
            for ($i=0;$i<$coun;$i++){
                $taskTime=$dat[$i].task_time;
                datea[$taskTime] = "任务";
                array[$i] = $taskTime;
            }
            console.log(datea);
            var ins1 = laydate.render({
                elem: '#test1',
                show:true,
                position: 'static',
                calendar: true,
                mark: datea,
                done: function(value, date){
                    var jump = false;
                    for(var i=0;i<array.length;i++){
                       if(array[i]==value){
                            jump = true;
                            break;
                       }
                    }
                    if(jump){
                       window.location.href="task_list.php";
                    }
            }

            });
        }




    },
    error: function (data) {

    }


});

    $.ajax({
        type: 'post',
        cache: false,
        url: '../../php/user/query_task_user.php',
        data: {
            "user":$user,
        },
        dataType: 'json',
        success: function (data) {
            $coun = data.count;
            $dat = data.data;
            $timeOver=$dat[0].over_time;
            var taskToalSelf=document.getElementById("task-title-self");
            taskToalSelf.innerHTML="总共有："+$coun+"项"+"&nbsp;&nbsp;&nbsp;&nbsp;"+"最新一项任务截至时间："+$timeOver;;
            layui.use('laydate', function(){
                var laydate = layui.laydate;
            });
            $fristTask=$dat[0].content;


        },
        error: function (data) {

        }


    });
    if($('#user').val()===""){
        layer.msg("您还没有登陆哦！");
        window.location.href="../loginU.html";

    }

//获取任务信息
    $.ajax({
        type: 'post',
        cache: false,
        url: '../../php/user/select_taskAll.php',
        data: {
        },
        dataType: 'json',
        success: function (data) {
            $coun = data.count;
            $dat = data.data;
            $timeOver=$dat[0].time_over;
            $taskFrist=$dat[0].task_content;
            $taskFrist=$taskFrist.substr(0.,100);
            var taskToal=document.getElementById("task-title-all");
            taskToal.innerHTML="已发布："+$coun+"项"+"&nbsp;&nbsp;&nbsp;&nbsp;"+"最新一项任务截至时间："+$timeOver;
            var userTask=document.getElementById("user_task");
            userTask.innerHTML=$taskFrist+"......";
            for ($i = 0; $i < $coun; $i++) {
                $id = $dat[$i].id;
                $user = $dat[$i].task_admin;
                $title=$dat[$i].title;
                $time=$dat[$i].time_over;
                $task_a=$dat[$i].task_a;
                $user_a=$dat[$i].user_a;
                $remark=$dat[$i].remark;
                $content=$dat[$i].task_content;
                $addtime=$dat[$i].task_time;
                $url=$dat[$i].url;00
                $complete=$dat[$i].complete;
                $msg="已被托管";
                $date=$addtime;
                if($user_a===""){
                    $li = $("<div id=" + $id + " class=\"layui-card\" id=\"card\">\n" + "<hr class=\"layui-bg-red\">" +
                        "<div class=\"layui-card-header\">" + "任务详情：" + "<button id='file' class=\"layui-btn layui-btn-xs\" >" + "<a href='" + $url + "' download='' style='color: white'>" + "附件下载" + "</a>" + "</button>" + "<a id='overTime'>" + "任务截至时间：" + $time + "</a>" + "<a id='overTime'>" + "完成时间：" +$complete+ "</a>" + "</div>" +
                        "                    <div class=\"layui-card-body\">\n" + $content + "<br>" +
                        "<hr>" + "<div class=\"layui-card-header\">" + "任务：" + "<a id='overTime'>" + "接受任务的成员：" + "<span id="+"id"+$id+" ></span>"+$user_a + "</a>" + "<button id="+"ace"+$id+" style='float: right;margin-top: 8px;margin-right: 10px' class=\"layui-btn layui-btn-xs layui-btn-normal\" onclick='accept("+$id+" \""+$task_a+"\")'>接受任务</button>" + "</div>" +
                        $task_a +
                        "<hr>" + "<div class=\"layui-card-header\">" + "备注：" + "</div>" +
                        $remark + "<br>" +
                        "<span id=\"time\">" + "发布时间：" + $date + "&nbsp;|&nbsp;" + "发布人：" + $user + "</span>" +
                        "<br>\n" +
                        "</div>\n" +
                        "</div>");
                }
                else {
                    $li = $("<div id=" + $id + " class=\"layui-card\" id=\"card\">\n" + "<hr class=\"layui-bg-red\">" +
                        "<div class=\"layui-card-header\">" + "任务详情：" + "<button id='file' class=\"layui-btn layui-btn-xs\" >" + "<a href='" + $url + "' download='' style='color: white'>" + "附件下载" + "</a>" + "</button>" + "<a id='overTime'>" + "任务截至时间：" + $time + "</a>" + "<a id='overTime'>" + "完成时间："+$complete + "</a>" + "</div>" +
                        "                    <div class=\"layui-card-body\">\n" + $content + "<br>" +
                        "<hr>" + "<div class=\"layui-card-header\">" + "任务：" + "<a id='overTime'>" + "接受任务的成员：" + $user_a + "</a>" + "<button id='acceptA' class=\"layui-btn layui-btn-primary layui-btn-xs\" onclick='accept(" + $task_a + ")'>"+$msg+"</button>" + "</div>" +
                        $task_a +
                        "<hr>" + "<div class=\"layui-card-header\">" + "备注：" + "</div>" +
                        $remark + "<br>" +
                        "<span id=\"time\">" + "发布时间：" + $date + "&nbsp;|&nbsp;" + "发布人：" + $user + "</span>" +
                        "<br>\n" +
                        "</div>\n" +
                        "</div>");
                }
                $("#uul").append($li);

            }
        },
        error: function (data) {
            layer.msg("您还没有任何任务哦，");
        }
    });




    //接受任务时
        function accept(id ,task) {
            $user=$('#user').val();
                layer.confirm('您真的要接受次任务吗？', function(index) {

                    $.ajax({
                        type:'post',
                        cache:'cache',
                        url:'../../php/user/task_accept.php',
                        data:{
                            "id":id,
                            "user_a":$user,
                            "task":task,
                        },
                        dataType:'json',
                        success:function (dat) {
                            layer.msg(dat.message);
                            $add_user="id"+id;
                            $accept="ace"+id;
                            var accept=document.getElementById($accept);
                            var addUser=document.getElementById($add_user);
                            addUser.innerHTML=$user;
                            accept.style.display="none";
                        },
                        error:function (dat) {
                            layer.msg("接受此任务失败！");
                        },

                    });


                })

        }
    var idd=document.getElementById("id").value;
    var uploadUrl = '../../php/user/upload.php?id='+idd;
    //文件选择完毕时
    function FileChangeFn(event) {
        $('.opst_txt').text('重新选择文件');
        $('.send_btn').show();
        var event = event || window.event,
            dom = '',
            ofile = $("#oFile").get(0).files[0],
            otype = ofile.type || '获取失败',
            osize = ofile.size / 1054000,
            ourl = window.URL.createObjectURL(ofile); //文件临时地址
        $('#file_type').text("选择上传文件类型：" + otype);
        $('#file_size').text("选择上传文件大小，共" + osize.toFixed(2) + "MB。");

        console.log("文件类型：" + otype); //文件类型
        console.log("文件大小：" + osize); //文件大小

        if ('video/mp4' == otype || 'video/avi' == otype || 'video/x-msvideo' == otype) {
            layer.msg("请上传图片");
            return false;
        }
        if ('audio/mp3' == otype || 'audio/wav' == otype  || 'audio/x-m4a' == otype) {
            layer.msg("请上传图片");
            return false;
        }
        if ('image/jpeg' == otype || 'image/png' == otype || 'image/gif' == otype) {
            dom = '<img id="photo" width="100px"  alt="我是image图片文件" src=' + ourl + ' title="" />';
        }
        if ('zip' == otype) {
            dom = '<img id="photo" width="100px"  alt="我是压缩文件" src=' + ourl + ' title="" />';
        }
        $('#file_box').html(dom);
    };

    //侦查附件上传情况 ,这个方法大概0.05-0.1秒执行一次
    function OnProgRess(event) {
        var event = event || window.event;
        //console.log(event);  //事件对象
        console.log("已经上传：" + event.loaded); //已经上传大小情况(已上传大小，上传完毕后就 等于 附件总大小)
        //console.log(event.total);  //附件总大小(固定不变)
        var loaded = Math.floor(100 * (event.loaded / event.total)); //已经上传的百分比
        $("#speed").html(loaded + "%").css("width", loaded + "%");
    };

    //开始上传文件
    function UploadFileFn() {


        var file=document.getElementById("oFile");
        fileV=file.value;
        if(fileV===""){
            layer.msg("您还没有选择任何文件哦")
        }
        else {

            $('.speed_box').show();
            var oFile = $("#oFile").get(0).files[0], //input file标签
                formData = new FormData(); //创建FormData对象
            xhr = $.ajaxSettings.xhr(); //创建并返回XMLHttpRequest对象的回调函数(jQuery中$.ajax中的方法)
            formData.append("myFile", oFile); //将上传name属性名(注意：一定要和 file元素中的name名相同)，和file元素追加到FormData对象中去

            $.ajax({
                type: "POST",
                url: uploadUrl, // 后端服务器上传地址
                data: formData, // formData数据
                cache: false, // 是否缓存
                async: true, // 是否异步执行
                processData: false, // 是否处理发送的数据  (必须false才会避开jQuery对 formdata 的默认处理)
                contentType: false, // 是否设置Content-Type请求头
                dataType: 'json',
                xhr: function () {
                    if (OnProgRess && xhr.upload) {
                        xhr.upload.addEventListener("progress", OnProgRess, false);
                        return xhr;
                    }
                },
                success: function (dat) {

                    $("#speed").html("上传成功");
                    var url=document.getElementById("img-url");
                    url.value=dat.src;
                },
                error: function (dat) {
                    $("#speed").html("上传失败");

                    layer.msg('上传失败！');
                }
            });
        }
    }

            $.ajax({
                type: 'post',
                cache: 'false',
                url: '../../php/user/query_user.php',
                data: {
                    "user": $user,
                },
                dataType: 'Json',
                success: function (dat) {
                    var user_name=document.getElementById("user_name"),
                        user_tel=document.getElementById("user_tel"),
                        user_email=document.getElementById("user_email"),
                        user_class=document.getElementById("user_class"),
                    userA=document.getElementById("userA"),
                    passA=document.getElementById("passA"),
                    tel=document.getElementById("tel"),
                        email=document.getElementById("email"),
                    classA=document.getElementById("classA"),
                    id=document.getElementById("id"),
                    headImg=document.getElementById("headImg"),
                    img=document.getElementById("img-url");

                    id.value=dat.data[0].id;
                    tel.value=dat.data[0].tel;
                    img.value=dat.data[0].img;
                    classA.value=dat.data[0].class;
                    email.value=dat.data[0].email;
                    userA.value=dat.data[0].user;
                    $dat=dat.data[0];
                    $admin=$dat.admin;
                    user_class.innerHTML=$dat.class;
                    user_tel.innerHTML=$dat.tel;
                    user_email.innerHTML=$dat.email;
                    user_name.innerHTML=dat.data[0].user;
                     headImg.src=dat.data[0].img;


                    $.ajax({
                        type: 'post',
                        cache: false,
                        url: '../../php/user/select_notice.php',
                        data: {
                            "admin":$admin,
                        },
                        dataType: 'json',
                        success: function (data) {
                            $dat = data.data
                            $coun = data.count;
                            $notice=$dat[0].content;
                            var not=document.getElementById("notice"),
                                user_notice=document.getElementById("user_notice");
                            not.innerHTML=$notice;
                            user_notice.innerHTML=$notice;

                            for ($i = 0; $i < $coun; $i++) {
                                $id = $dat[$i].id;
                                $user = $dat[$i].no_admin;
                                $title=$dat[$i].title;
                                $content=$dat[$i].content;
                                $addtime=$dat[$i].no_addtime;
                                var date=new Date(parseInt($addtime)*1000);
                                Y=date.getFullYear()+'年';
                                M=(date.getMonth()+1<10?'0'+(date.getMonth()+1):date.getMonth()+1)+'月';
                                D=date.getDate()+'日';
                                h=date.getHours()+':';
                                m=date.getMinutes()+':';
                                s=date.getSeconds();
                                $date=Y+M+D+h+m+s;
                                if($i===0){
                                    $li = $(" <li class=\"layui-timeline-item\">\n" +
                                        "                        <i class=\"layui-icon layui-timeline-axis\"></i>\n" +
                                        "                        <div class=\"layui-timeline-content layui-text\">\n" +
                                        "                            <div class=\"layui-timeline-title\">"+$date+"&nbsp;&nbsp;"+"主题："+$title+"&nbsp;&nbsp;内容："+$content+"</div>\n" +
                                        "                        </div>\n" +
                                        "                    </li>");
                                }
                                else if($i===$coun-1) {
                                    $li = $(" <li class=\"layui-timeline-item\">\n" +
                                        "<i class=\"layui-icon layui-anim layui-anim-rotate layui-anim-loop layui-timeline-axis\"></i>"+
                                        "                        <div class=\"layui-timeline-content layui-text\">\n" +
                                        "                            <div class=\"layui-timeline-title\">" + $date + "&nbsp;&nbsp;" + "主题：" + $title + "&nbsp;&nbsp;内容：" + $content + "</div>\n" +
                                        "                        </div>\n" +
                                        "                    </li>");

                                }
                                else {
                                    $li = $(" <li class=\"layui-timeline-item\">\n" +
                                        "<i class=\"layui-icon layui-timeline-axis\"></i>"+
                                        "                        <div class=\"layui-timeline-content layui-text\">\n" +
                                        "                            <div class=\"layui-timeline-title\">" + $date + "&nbsp;&nbsp;" + "主题：" + $title + "&nbsp;&nbsp;内容：" + $content + "</div>\n" +
                                        "                        </div>\n" +
                                        "                    </li>");

                                }
                                $("#notice-list").append($li);
                            }


                        },
                        error: function (data) {
                            layer.msg("暂无任何公告");
                        }
                    });
                },
                error: function (dat) {
                    layer.msg("请检查网络是否正常");
                }


            });


function update() {
       $id=$('#id').val();
        $user=$('#userA').val();
        $class=$('#classA').val();
        $tel=$('#tel').val();
        $url=$('#img-url').val();
        $email=$('#email').val();
        $pass=$('#passA').val();

               $.ajax({
                   type:'post',
                   cache:'false',
                  url:'../../php/user/user_update_user.php',
                   data:{
                      "id":$id,
                       "user":$user,
                       "class":$class,
                       "tel":$tel,
                       "email":$email,
                       "url":$url,
                       "pass":$pass,

                   },
                   dataType:'json',
                   success:function (dat) {
                       layer.msg(dat.message);

                   },
                   error:function (dat) {
                       layer.msg("修改失败");
                   }

               });


}

function out() {
    layer.confirm('真的要退出吗？', function(index) {
        window.location.href="../../php/user/clearSession.php";
    })
}
</script>

</body>
</html>